import Vue from 'vue';
import Vuex from 'vuex';
import getters from './getters';


Vue.use(Vuex);//全局使用Vuex这个插件

//定义一个store对象
const store = new Vuex.Store({
    //定义要存放的数据
    state: {
        //用户名
        username: localStorage.getItem('ms_username'),
        //令牌
        token:localStorage.getItem('token'),
        id:''
    },
    mutations: {
        setUserName(state,name) {
            
            state.username = name.userName;
        },
        set_token(state, token) {
            state.token = token;
            state.refresh_token=token
            // sessionStorage.token = token
          },
          del_token(state) {
            state.token = ''
            sessionStorage.removeItem('token')
          },
          setUserId(state,id){
            state.id=id
          }
    },
    getters
}
);

export default store; //导出store对象